package com.hisan.freeride.home.adapter;

import android.view.View;

import com.github.library.BaseQuickAdapter;
import com.github.library.BaseViewHolder;

import com.hisan.freeride.R;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.home.model.Exchange;


import java.util.List;

/**
 * Created by yu on 2017/1/17.
 */

public class ExChangeAdapter extends BaseQuickAdapter<Exchange, BaseViewHolder> {
    public ExChangeAdapter(List<Exchange> data) {
        super(R.layout.price_item,data);
    }
    private ButtonClickListener mButtonClickListener;

    @Override
    protected void convert(BaseViewHolder holder, Exchange water) {
        holder.setText(R.id.name,water.getName());
        holder.setText(R.id.time,water.getCreate_time());
        if (CollectionUtils.isNullOrEmpty(water.getCodedata().getTakecode())){
            holder.getView(R.id.status).setVisibility(View.VISIBLE);
            holder.getView(R.id.status2).setVisibility(View.GONE);
            if (water.getHandle()==1){
                holder.setText(R.id.status,"已完成");
            }else {
                holder.setText(R.id.status,"未完成");
            }
        }else{
            holder.getView(R.id.status).setVisibility(View.GONE);
            holder.getView(R.id.status2).setVisibility(View.VISIBLE);
            holder.setText(R.id.status2,"查看兑换码");
            holder.getView(R.id.status2).setOnClickListener(v -> {
                if (mButtonClickListener!=null){
                    mButtonClickListener.onClick(water);
                }
            });

        }
    }
    public void setButtonClickListener(ButtonClickListener listener) {
        mButtonClickListener = listener;
    }

    /**
     * 按钮的点击监听
     */
    public interface ButtonClickListener {
        void onClick(Exchange exchange);
    }
}
